package com.xiyuan.smartutils.template.engine.expression.primitive;

import com.xiyuan.smartutils.template.engine.VariableMap;
import com.xiyuan.smartutils.template.engine.exception.ExpressionException;

/**
 * 小数原型，float/double，零点开头后面为数字，或非零数字开头数字和一个点号连贯出现"^(0|[1-9]\\d*)(\\.\\d+)?$"
 * 
 * @version v1.0.0 @author lgz 2020年11月1日 新建与整理
 */
public class _Decimal extends Primitive
{
    private static final long serialVersionUID = 1L;
    private final String value;
    
    public _Decimal(String path,int line, int column, String value)
    {
        super(path, line, column);
        this.value = value;
    }
    
    @Override
    public int getType()
    {
        return DECIMAL;
    }
    
    @Override
    public Object build(VariableMap variableMap) throws ExpressionException
    {
        return Double.parseDouble(value);
    }
    
    @Override
    public String toString()
    {
        return value;
    }
    
    public double getDouble()
    {
        return Double.parseDouble(value);
    }
    
    public float getFloat()
    {
        return Float.parseFloat(value);
    }
}
